package fourfaith.com.ff_sl21_app;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

/**
 * 确认提示框的公用活动页
 * @author administrator
 *
 */
public class CommonMsgDialogActivity extends Activity {

	private TextView title,content;
	private View cancelBtn;
	private OnDialogClickListener dialogClickListener;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//隐藏标题栏
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		//绑定对应的层
		setContentView(R.layout.message_dialog);
		initViews();
		
		Intent intent=getIntent();  
		String content = intent.getStringExtra("content");
		if(content != null){
			String title = intent.getStringExtra("title");
			
			initData(title, content);
		}
		
		initListeners();
	}

	private void initViews() {
		initWindow();
		//实列化控件
		title = (TextView) findViewById(R.id.title);
		content = (TextView) findViewById(R.id.content);
		cancelBtn = findViewById(R.id.btn_cancel);
	}

	private void initData(String msgTitle, String msgContent) {
		if(msgTitle != null) 
			title.setText(msgTitle);
		content.setText(msgContent);
	}
	
	private void initWindow() {
		//自定义windows弹窗的样式
		getWindow().setBackgroundDrawable(new ColorDrawable(0));
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN |
				WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	}
	
	private void initListeners() {
		//取消按钮取点击监听
		cancelBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				//关闭当前的activity
				finish();
				if(dialogClickListener != null){
					dialogClickListener.onCancelClick();
				}
			}
		});
	}

	public void setOnDialogClickListener(OnDialogClickListener clickListener){
		dialogClickListener = clickListener;
	}


	public interface OnDialogClickListener{
		void onCancelClick();
	}
}
